﻿namespace MVVMBasedDialogs.ViewModel
{
    using GalaSoft.MvvmLight;
    using System.Collections.ObjectModel;
    using System.Windows.Input;
    using GalaSoft.MvvmLight.Command;

    class OrderViewModel : ViewModelBase
    {
        ObservableCollection<CustomerViewModel> _customers =
            new ObservableCollection<CustomerViewModel>()
            {
                new CustomerViewModel() {FirstName = "Muhammad", LastName="Siddiqui"},
                new CustomerViewModel() {FirstName = "Ryan", LastName = "Vice"}
            };

        public ObservableCollection<CustomerViewModel> Customers
        {
            get
            {
                return _customers;
            }
        }

        CustomerViewModel _selectedCustomer;
        public CustomerViewModel SelectedCustomer
        {
            get
            {
                return _selectedCustomer;
            }
            set
            {
                _selectedCustomer = value;
                RaisePropertyChanged("SelectedCustomer");
            }
        }

        ICommand _showCustomerDetailsCommand;
        public ICommand ShowCustomerDetailsCommand
        {
            get
            {
                if (_showCustomerDetailsCommand == null)
                {
                    _showCustomerDetailsCommand = 
                        new RelayCommand(() =>
                            {
                                DialogService.Instance.ShowDialog(SelectedCustomer);
                            },
                            () => this.SelectedCustomer != null);
                }

                return _showCustomerDetailsCommand;
            }
        }
    }
}
